//
//  TextField_Base.swift
//  Demo_01
//
//  Created by apple on 2020/7/21.
//  Copyright © 2020 Joseph. All rights reserved.
//

import SwiftUI

// TextField类似于UIKit中的UITextField，用于实现用户的文字内容的输入。
struct TextField_Base: View {
    @State var username : String
    @State var nickname : String
    @State var password : String
    
    var body: some View {
        
        VStack{
            
            Text("Your username is \(username)!")
            
            Text("Your nickname is \(nickname)!")
            
            TextField("User Name", text: $username, onEditingChanged: { (value) in
                print("onEditingChanged:\(self.username)")
            }) {
                print("onCommit:\(self.username)")
            }.textFieldStyle(RoundedBorderTextFieldStyle())
            
            TextField("Nick Name", text: $nickname)
                .textFieldStyle(RoundedBorderTextFieldStyle())
            
            // 相当于UITexfield的secureTextEntry的属性设置为true时的情况。
            Text("Your password is \(password)!")
            SecureField("Your password", text: $password) {
                print("Your password is \(self.password)!")
            }
            .textFieldStyle(RoundedBorderTextFieldStyle())
        }
        .padding()
        

        
    }
}

struct TextField_Base_PreViews: PreviewProvider {
    static var previews: some View {
        TextField_Base(username: "name", nickname: "nickname", password: "password")
    }
}
